package com.dongdongshop.mq;

import com.aliyuncs.exceptions.ClientException;
import com.dongdongshop.service.SmsService;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Component
// 配置消费者监听的topic和消费者的组
@RocketMQMessageListener(topic = "sms_code",consumerGroup = "dongdongshop1")
public class SmsMQ implements RocketMQListener<String> {
    @Autowired
    private SmsService smsService;
    @Resource
    private RedisTemplate redisTemplate;
    @Override
    public void onMessage(String s) {
        System.out.println("s"+s);
        try {
              String temp[]=s.split(",");
              smsService.sendSms(temp[0],temp[1]);
            System.out.println("消费成功");
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("消费失败");
        }

    }
}
